package br.com.iswe.core.pool;

import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;


public class SoftHashMap<K, V> {

	private Map<K, SoftReference<V>> pool = new HashMap<K, SoftReference<V>>();
	
	public void put(K key, V value) {
		//cria uma referencia soft
		SoftReference<V> softReference = new SoftReference<V>(value);
		//adiciona no pool
		pool.remove(key);
		pool.put(key, softReference);
	}

	public V get(K key) {
		SoftReference<V> softReference = pool.get(key);
		if(softReference != null){
			return softReference.get();
		}
		return null;
	}
}
